<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Docs For Class Services_JSON</title>
	<link rel="stylesheet" type="text/css" href="../media/style.css">
	<link rel="stylesheet" type="text/css" href="../media/php-ext.css">
	<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
</head>
<body>

<div id="header">
	<h1><img src="../media/php-ext2.png" alt="PHP-Ext Logo" title="PHP-Ext" width="110" height="34" /></h1>
	<div>
		<div id="legend">The Web 2.0 PHP Widget Library using Ext JS</div>


		<!-- <div class="banner-title">Services_JSON</div> -->

		<ul id="menu">
			<li><a href="../../../" target="_top">Home</a></li>
			<li><a href="../../../?id=docs" target="_top">Docs</a></li>
			<li><a href="../../../examples" target="_top">Samples</a></li>
			<li><a href="http://php-ext.quimera-solutions.com/blog">Blog</a></li>
			<li><a href="http://php-ext.quimera-solutions.com/?id=download" target="_top">Download</a></li>
		</ul>
		</div>
		<div id="topbanner">
		<script type="text/javascript"><!--
		google_ad_client = "pub-1364424610077556";
		/* PHP-Ext TopBanner */
		google_ad_slot = "0256386108";
		google_ad_width = 468;
		google_ad_height = 60;
		//-->
		</script>
		<script type="text/javascript"
		src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
		</script>
		</div> 
	</div>
    <div class="header-menu">
	  <div>
	  <span class="package">Services_JSON</span> : <span class="subpackage"></span>
      
                                                    
                      		[ <a href="../classtrees_Services_JSON.html" class="menu">class tree</a> ]
		[ <a href="../elementindex_Services_JSON.html" class="menu">index</a> ]
            [ <a href="../elementindex.html" class="menu">all elements</a> ]
	  </div>
    </div>
</table>

</div>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="left-menu">
  <tr valign="top">
    <td width="195" class="menu">
		<div class="package-title">Services_JSON</div>
  <div class="package">
	<div id="todolist">
			<p><a href="../todolist.html">Todo List</a></p>
	</div>
	</div>
      <b>Packages:</b><br />
  <div class="package">
              <a href="../li_PhpExt.html">PhpExt</a><br />
              <a href="../li_PhpExtUx.html">PhpExtUx</a><br />
              <a href="../li_Services_JSON.html">Services_JSON</a><br />
      	</div>
      <br />
                        <b>Files:</b><br />
        <div class="package">
				<span style="padding-left: 1em;"><a href="../Services_JSON/_PhpExt---Lib---json.php.html">json.php</a></span><br />
	  </div>
            <br />
                  <b>Classes:</b><br />
        <div class="package">
		    		<a href="../Services_JSON/Services_JSON.html">Services_JSON</a>    	 <br />
	    		<a href="../Services_JSON/Services_JSON_Error.html">Services_JSON_Error</a>    	 <br />
	  </div>
                </td>
    <td>
	  <div class="docs-content"></div>
      <table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">
		
<h1>Class: Services_JSON</h1>
Source Location: /PhpExt/Lib/json.php<br /><br />

<h2 class="class-name">Class Services_JSON</h2>

<a name="sec-description"></a>
<div class="info-box">
	<div class="info-box-title">Class Overview</div>
	<div class="nav-bar">
					<span class="disabled">Class Overview</span>
						
													| <a href="#sec-method-summary">Method Summary</a> | <a href="#sec-methods">Methods Detail</a>
								</div>
	<div class="info-box-body">
		<table width="100%" border="0">
		<tr><td valign="top" width="60%" class="class-overview">

        		<p align="center" class="short-description"><strong>Converts to and from JSON format.
</strong></p>
<span class="description"><p>Brief example of use:</p><p><ol><li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;create&nbsp;a&nbsp;new&nbsp;instance&nbsp;of&nbsp;Services_JSON</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$json&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><a href="../Services_JSON/Services_JSON.html#methodServices_JSON">Services_JSON</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;convert&nbsp;a&nbsp;complexe&nbsp;value&nbsp;to&nbsp;JSON&nbsp;notation,&nbsp;and&nbsp;send&nbsp;it&nbsp;to&nbsp;the&nbsp;browser</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$value&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">'foo'</span><span class="src-sym">,&nbsp;</span><span class="src-str">'bar'</span><span class="src-sym">,&nbsp;</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">1</span><span class="src-sym">,&nbsp;</span><span class="src-num">2</span><span class="src-sym">,&nbsp;</span><span class="src-str">'baz'</span><span class="src-sym">)</span><span class="src-sym">,&nbsp;</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">3</span><span class="src-sym">,&nbsp;</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">4</span><span class="src-sym">)))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$output&nbsp;</span>=&nbsp;<span class="src-var">$json</span><span class="src-sym">-&gt;</span><a href="../Services_JSON/Services_JSON.html#methodencode">encode</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;print<span class="src-sym">(</span><span class="src-var">$output</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;prints:&nbsp;[&quot;foo&quot;,&quot;bar&quot;,[1,2,&quot;baz&quot;],[3,[4]]]</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;<span class="src-comm">//&nbsp;accept&nbsp;incoming&nbsp;POST&nbsp;data,&nbsp;assumed&nbsp;to&nbsp;be&nbsp;in&nbsp;JSON&nbsp;notation</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$input&nbsp;</span>=&nbsp;<a href="http://www.php.net/file_get_contents">file_get_contents</a><span class="src-sym">(</span><span class="src-str">'php://input'</span><span class="src-sym">,&nbsp;</span><span class="src-num">1000000</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;<span class="src-var">$value&nbsp;</span>=&nbsp;<span class="src-var">$json</span><span class="src-sym">-&gt;</span><a href="../Services_JSON/Services_JSON.html#methoddecode">decode</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
</ol></p></span>
		<p class="notes">
			Located in <a class="field" href="_PhpExt---Lib---json.php.html">/PhpExt/Lib/json.php</a> [<span class="field">line <a href="../__filesource/fsource_Services_JSON__PhpExtLibjson.php.html#a115">115</a></span>]
		</p>

		
		<pre></pre>

		
		
		
		</td>

		
				<td valign="top" width="20%" class="class-overview">
		<p align="center" class="short-description"><strong><a href="#sec_methods">Methods</a></strong></p>
		<ul>
		  		  <li><a href="../Services_JSON/Services_JSON.html#methodServices_JSON">Services_JSON</a></li>
		  		  <li><a href="../Services_JSON/Services_JSON.html#methoddecode">decode</a></li>
		  		  <li><a href="../Services_JSON/Services_JSON.html#methodencode">encode</a></li>
		  		  <li><a href="../Services_JSON/Services_JSON.html#methodisError">isError</a></li>
		  		</ul>
		</td>
		
		</tr></table>
		<div class="top">[ <a href="#top">Top</a> ]</div>
	</div>
</div>





	<a name="sec-method-summary"></a>
	<div class="info-box">
		<div class="info-box-title">Method Summary</span></div>
		<div class="nav-bar">
			<a href="#sec-description">Class Overview</a>
									    					| <span class="disabled">Method Summary</span> | <a href="#sec-methods">Methods Detail</a>
		</div>
		<div class="info-box-body">
			<div class="method-summary">
				<table border="0" cellspacing="0" cellpadding="0" class="method-summary">
																																																<div class="method-definition">
											<tr><td class="method-definition"><span class="method-result">Services_JSON</span>&nbsp;&nbsp;</td>
										<td class="method-definition"><a href="#Services_JSON" title="details" class="method-name">Services_JSON</a>()&nbsp;&nbsp;</td>
					<td class="method-definition">constructs a new JSON instance</td></tr>
				</div>
																<div class="method-definition">
											<tr><td class="method-definition"><span class="method-result">mixed</span>&nbsp;&nbsp;</td>
										<td class="method-definition"><a href="#decode" title="details" class="method-name">decode</a>()&nbsp;&nbsp;</td>
					<td class="method-definition">decodes a JSON string into appropriate variable</td></tr>
				</div>
																<div class="method-definition">
											<tr><td class="method-definition"><span class="method-result">mixed</span>&nbsp;&nbsp;</td>
										<td class="method-definition"><a href="#encode" title="details" class="method-name">encode</a>()&nbsp;&nbsp;</td>
					<td class="method-definition">encodes an arbitrary variable into JSON format</td></tr>
				</div>
																<div class="method-definition">
											<tr><td class="method-definition"><span class="method-result">void</span>&nbsp;&nbsp;</td>
										<td class="method-definition"><a href="#isError" title="details" class="method-name">isError</a>()&nbsp;&nbsp;</td>
					<td class="method-definition"></td></tr>
				</div>
												</table>
			</div>
			<br /><div class="top">[ <a href="#top">Top</a> ]</div>
		</div>
	</div>


	<a name="sec-methods"></a>
	<div class="info-box">
		<div class="info-box-title">Methods</div>
		<div class="nav-bar">
			<a href="#sec-description">Class Overview</a>
																			| <a href="#sec-method-summary">Method Summary</a> | <span class="disabled">Methods Detail</span>
					</div>
		<div class="info-box-body">
			<a name='method_detail'></a>

<a name="methodServices_JSON" id="Services_JSON"><!-- --></a>
<div class="evenrow">

<div class="method-header">
	<span class="method-title">Constructor Services_JSON</span>&nbsp;&nbsp;<span class="smalllinenumber">[line <a href="../__filesource/fsource_Services_JSON__PhpExtLibjson.php.html#a133">133</a>]</span>
</div>
<br />

	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code-border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">&nbsp;
		<code>Services_JSON Services_JSON(
[int
$use = 0]&nbsp;
)</code>
    </td></tr></table>
    </td></tr></table><br /></div>

	<p align="center" class="short-description"><strong>constructs a new JSON instance
</strong></p>

			<strong>Parameters:</strong><br />
			<table border="0" cellspacing="0" cellpadding="0">
					<tr><td class="indent">
				<span class="var-type">int</span>&nbsp;&nbsp;</td>
				<td>
				<span class="var-name">$use:&nbsp;</span></td>
				<td>
				<span class="var-description"> <p>object behavior flags; combine with boolean-OR</p><p>possible values: <ul><li>SERVICES_JSON_LOOSE_TYPE:  loose typing.
                                   &quot;{...}&quot; syntax creates associative arrays
                                   instead of objects in decode().</li><li>SERVICES_JSON_SUPPRESS_ERRORS:  error suppression.
                                   Values which can't be encoded (e.g. resources)
                                   appear as NULL instead of throwing errors.
                                   By default, a deeply-nested resource will
                                   bubble up with an error, so all return values
                                   from encode() should be checked with isError()</li></ul></p></span>			</td></tr>
				</table>

	<br />
	

		
		<br />
	<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<a name="methoddecode" id="decode"><!-- --></a>
<div class="oddrow">

<div class="method-header">
	<span class="method-title">decode</span>&nbsp;&nbsp;<span class="smalllinenumber">[line <a href="../__filesource/fsource_Services_JSON__PhpExtLibjson.php.html#a484">484</a>]</span>
</div>
<br />

	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code-border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">&nbsp;
		<code>mixed decode(
string
$str&nbsp;
)</code>
    </td></tr></table>
    </td></tr></table><br /></div>

	<p align="center" class="short-description"><strong>decodes a JSON string into appropriate variable
</strong></p>

			<strong>Parameters:</strong><br />
			<table border="0" cellspacing="0" cellpadding="0">
					<tr><td class="indent">
				<span class="var-type">string</span>&nbsp;&nbsp;</td>
				<td>
				<span class="var-name">$str:&nbsp;</span></td>
				<td>
				<span class="var-description"> JSON-formatted string</span>			</td></tr>
				</table>

	<br />
	<strong>API Tags:</strong><br />
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="indent"><strong>Return:</strong>&nbsp;&nbsp;</td><td>number, boolean, string, array, or object                    corresponding to given JSON input string.                    See argument 1 to Services_JSON() above for object-output behavior.                    Note that decode() always returns strings                    in ASCII or UTF-8 format!</td>
  </tr>
  <tr>
    <td class="indent"><strong>Access:</strong>&nbsp;&nbsp;</td><td>public</td>
  </tr>
</table>
<br />


		
		<br />
	<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<a name="methodencode" id="encode"><!-- --></a>
<div class="evenrow">

<div class="method-header">
	<span class="method-title">encode</span>&nbsp;&nbsp;<span class="smalllinenumber">[line <a href="../__filesource/fsource_Services_JSON__PhpExtLibjson.php.html#a237">237</a>]</span>
</div>
<br />

	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code-border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">&nbsp;
		<code>mixed encode(
mixed
$var&nbsp;
)</code>
    </td></tr></table>
    </td></tr></table><br /></div>

	<p align="center" class="short-description"><strong>encodes an arbitrary variable into JSON format
</strong></p>

			<strong>Parameters:</strong><br />
			<table border="0" cellspacing="0" cellpadding="0">
					<tr><td class="indent">
				<span class="var-type">mixed</span>&nbsp;&nbsp;</td>
				<td>
				<span class="var-name">$var:&nbsp;</span></td>
				<td>
				<span class="var-description"> any number, boolean, string, array, or object to be encoded.                            see argument 1 to Services_JSON() above for array-parsing behavior.                            if var is a strng, note that encode() always expects it                            to be in ASCII or UTF-8 format!</span>			</td></tr>
				</table>

	<br />
	<strong>API Tags:</strong><br />
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="indent"><strong>Return:</strong>&nbsp;&nbsp;</td><td>JSON string representation of input var or an error if a problem occurs</td>
  </tr>
  <tr>
    <td class="indent"><strong>Access:</strong>&nbsp;&nbsp;</td><td>public</td>
  </tr>
</table>
<br />


		
		<br />
	<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
<a name="methodisError" id="isError"><!-- --></a>
<div class="oddrow">

<div class="method-header">
	<span class="method-title">isError</span>&nbsp;&nbsp;<span class="smalllinenumber">[line <a href="../__filesource/fsource_Services_JSON__PhpExtLibjson.php.html#a766">766</a>]</span>
</div>
<br />

	<div class="function">
    <table width="90%" border="0" cellspacing="0" cellpadding="1"><tr><td class="code-border">
    <table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td class="code">&nbsp;
		<code>void isError(

$data, [
$code = null]&nbsp;
)</code>
    </td></tr></table>
    </td></tr></table><br /></div>

	
			<strong>Parameters:</strong><br />
			<table border="0" cellspacing="0" cellpadding="0">
					<tr><td class="indent">
				<span class="var-type"></span>&nbsp;&nbsp;</td>
				<td>
				<span class="var-name">$data:&nbsp;</span></td>
				<td>
							</td></tr>
					<tr><td class="indent">
				<span class="var-type"></span>&nbsp;&nbsp;</td>
				<td>
				<span class="var-name">$code:&nbsp;</span></td>
				<td>
							</td></tr>
				</table>

	<br />
	
<strong>Information Tags:</strong><br />
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="indent"><strong>Todo:</strong>&nbsp;&nbsp;</td><td>Ultimately, this should just call PEAR::isError()</td>
  </tr>
</table>

		
		<br />
	<div class="top">[ <a href="#top">Top</a> ]</div>
</div>
		</div>
	</div>


        <div class="credit">
		    <hr class="separator" />
		    Documentation generated on Thu, 07 Aug 2008 21:16:03 -0500 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.0</a>
	      </div>
      </td></tr></table>
    </td>
  </tr>
  <tr>
	<td><div class="docs-content"></div></td>
  </tr>
</table>

<br style="clear:both;" />
<div id="footer">
PHP-Ext Open Source Project | <a href="http://php-ext.googlecode.com">http://php-ext.googlecode.com</a> | <a href="http://php-ext.quimera-solutions.com">http://php-ext.quimera-solutions.com</a> |
sergeiw at gmail.com
</div>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1324828-4");
pageTracker._initData();
pageTracker._trackPageview();
</script>


</body>
</html>